<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/11/8
 * Time: 18:06
 */
require_once('env.php');
require_once('functions.php');

$index_obj = getSysConfig();
//$product = array("remaining_time" => "2016-10-30 23:00:00", "products_id" => 1, "products_desc_images" => "http://www.ygqq.com/static/zt/red/images/c1.png", "products_img" => "http://www.ygqq.com/static/zt/red/images/c1.png", "products_name" => "玛莎拉蒂-Ghibli 2014款 3.0T 标准版", "products_price" => "1239", "products_currency" => "NT", "products_special_price" => "999", "products_sales_num" => 2132);

$product = getDefProduct();

$date_remain = date("Y/m/d H:i:s", strtotime($product['remaining_time']));

?>
<!DOCTYPE HTML>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title><?php echo $index_obj['title'] ?></title>
    <meta name="Keywords" content="<?php echo $index_obj['kewords']; ?>"/>
    <meta name="Description"
          content="<?php echo $index_obj['description']; ?>"/>
    <link href="style/css/activityTopic.css" rel="stylesheet" type="text/css">
    <script src="style/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="style/js/jquery.cityselect.js"></script>
    <script>
        $(function () {
            $("#area").citySelect({
                url: "city.php",
                required: false
            });
        });
    </script>
</head>
<body>
<div class="all_wrap">
    <div class="page_content">


        <div class="page_header_wrap">
            <div class="page_header header_style2">
                <a href="javascript:;" class="goLeft"><i class="icon_sys_goleft_f"></i></a>

                <div class="title_header"><?php echo $index_obj['title'] ?></div>
                <a href="javascript:;" class="fastApply"><i class="icon_sys_home"></i></a>
            </div>
        </div>


        <div class="topicBanner">
            <img src="<?php echo $product['products_img'] ?>"/>

            <div class="bannerbg"></div>
        </div>

        <div class="topicMain">
            <div class="TMtit"><?php echo $product['products_name'] ?></div>
            <div class="TMcon">
                <?php echo $product['products_desc'] ?>
            </div>
            <div class="TMstate">
                <label class="apply"><i class="acIcon_3"></i>目前已申請<span
                        class="f18 cf00"><?php echo $product['products_sales_num'] ?></span>人</label>
                <label class="count cf00" id="leftTime"></label>
            </div>
        </div>

        <div class="topicBox mt10" id="applydiv">
            <div class="TBtit">
                <span class="name">我要申請</span>
                <span class="line"></span>
            </div>
            <form name="form" id="form" action="" method="post">
                <div class="applyBox">
                    <dl>
                        <dd><i class="acIcon_4"></i><input type="text" placeholder="請輸入您的中文姓名" name="user_name"/></dd>
                        <dd><i class="acIcon_6"></i><input type="text" placeholder="請輸入您的手機" name="phone"/></dd>
                        <dd class="ddR3"><i class="acIcon_8"></i><input name="email" type="text"
                                                                        placeholder="郵箱必填，申請成功會發送通知郵件"/></dd>
                        <dd id="area" class="ddR3">
                            <i class="acIcon_7"></i>
                            <select class="prov col-xs-12 form-control" id="prov_id" style="margin-top: 10px;"></select>
                            <select class="city col-xs-12 form-control" id="city_id" style="margin-top: 10px;"
                                    disabled="disabled"></select>
                        </dd>
                        <dd class="ddR3">
                            <input class="input addr col-xs-12 form-control" type="text" id="address" name="address"
                                   maxlength="20" placeholder="詳細地址具體到街道門牌號" required>
                        </dd>
                    </dl>


                    <div class="btn">
                        <input id="wysq" type="button" class="ipt_btn" value="我要申請"/>
                    </div>
                    <div class="info">
                        <p class="c999"><span class="cf00 mr5">*</span>提交申請後，如有任何問題我們的工作人員會跟您郵件聯繫。</p>

                        <p class="cf00 f14" id="error_html"></p>
                    </div>
                </div>
            </form>
        </div>

        <div class="topicBox mt10">
            <div class="TBtit">
                <span class="name">商品詳情</span>
                <span class="line"></span>
            </div>
            <div class="topicDetail">
                <p style="text-align:center;">
                    <?php if ($product['products_desc_images']) {
                        $img_array = explode("||", $product['products_desc_images']);
                        foreach ($img_array as $img) {
                            ?>
                            <img src="<?php echo $img ?>" alt=""/>
                        <?php }
                    } ?>
                </p></div>
        </div>

        <div class="topicBox mt10">
            <div class="TBtit">
                <span class="name" style="width:14em"><?php echo $index_obj['footer_company'] ?></span>
                <span class="line"></span>
            </div>
        </div>

        <div class="page_footer_black mt10">
            <p>
                <?php echo $index_obj['footer_copyright'] ?>
                <br/>
            </p>
        </div>


    </div>
</div>


<div class="applyTools">
    <a href="#applydiv"><span><i class="acIcon_2"></i>我要申請</span></a>
</div>

<div style="display: none;">
    <?php echo str_replace('&nbsp;', '', htmlspecialchars_decode($index_obj['tongji_code'], ENT_QUOTES)) . '<br/>'; ?>
</div>
<script src="style/js/lefttime.js"></script>
<script src="style/js/topicsms.js"></script>
<script type="text/javascript">
    var _qianzhui = '<i class="acIcon_5"></i>';
    var _day = '<span class=" c666">天</span>';
    var _hour = ':';
    var _minute = ':';
    var _second = '.';
    var _end = '已結束';
    var private_end = '<span class="sbtn">已結束</span>';
    var gmt_end_time = <?php echo strtotime($date_remain) ?>;
    var now_time = <?php echo time() ?>;

    try {
        onload_leftTime(now_time);
    }
    catch (e) {
    }

    $(document).ready(function () {

        if (now_time >= gmt_end_time) {
            $('#wysq').removeClass("ipt_btn");
            $('#wysq').addClass("ipt_btn_no_bg");
            $('#wysq').unbind('click');
        }

        $(window).scroll(function (event) {
            var st;
            var scrollHeight = $(".topicBanner").height() + $(".topicMain").height() + 375;
            st = $(this).scrollTop();
            if (st >= scrollHeight) {
                $('.applyTools').addClass("open");
            } else {
                $('.applyTools').removeClass("open");
            }
        });
    });

    $("#wysq").click(function () {
        var obj = $('#form');
        var thisobj = $(this);
        thisobj.val('提交中...');
        thisobj.attr('disabled', true);
        var mobile = $("input[name='phone']").val();
        var realname = $("input[name='user_name']").val();
        var email = $("input[name='email']").val();

        var prov = $("#prov_id").val();
        var city = $("#city_id").val();
        var address = $("input[name='address']").val();

        if (!prov || !city || !address) {
            alert('地區和縣市必須選擇，詳細地址必須填寫');
            thisobj.attr('disabled', false);
            return;
        }

        if (!realname.match(/^[\u4E00-\u9FA5]{2,4}$/)) {
            alert('姓名必須是中文並且在2-4位之間！');
            thisobj.attr('disabled', false);
            return;
        }
        if (!mobile.match(/^[0]\d{9}$/)) {
            alert('請正確填寫手機號碼，首位是0的十位數字號碼');
            thisobj.attr('disabled', false);
            return;
        }
        if (!email.match(/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i)) {
            alert('請正確填寫郵箱！');
            thisobj.attr('disabled', false);
            return;
        }

        $.ajax({
            url: 'submit_action.php',
            type: 'post',
            data: {
                user_name: realname,
                phone: mobile,
                addr: prov + city + address,
                email: email,
                product_id: "<?php echo $product['products_id']?>"
            },
            cache: false,
            dataType: 'json',
            success: function (jsonObj) {
                if (jsonObj.code == "-1") {
                    window.location.href = jsonObj.href + "?msg=" + jsonObj.msg;
                } else {
                    window.location.href = jsonObj.href;
                }

                thisobj.attr('disabled', false);
                thisobj.val('我要申請');

            },
            error: function () {
                thisobj.attr('disabled', false);
                alert('異常');
            }
        });
    });
</script>
</body>
</html>
